﻿using Mathmall.Administration.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Mathmall.Administration.Data
{
    public class MenuEntityTypeConfiguration : IEntityTypeConfiguration<Menu>
    {
        public void Configure(EntityTypeBuilder<Menu> builder)
        {
            builder
                .ToTable(nameof(Menu))
                .ToTable(tableBuilder => tableBuilder.HasComment("菜单"));

            builder
                .HasKey(menu => menu.MenuID)
                .HasName("菜单id");

            builder
                .Property(menu => menu.MenuName)
                .HasColumnName("MenuName")
                .HasColumnType("nvarchar(256)")
                .HasComment("菜单名称")
                .IsRequired(true);

            builder
                .Property(menu => menu.MenuCode)
                .HasColumnName("MenuCode")
                .HasColumnType("int")
                .HasComment("菜单编码")
                .IsRequired(true);

            builder
                .Property(menu => menu.ParentId)
                .HasColumnName("ParentId")
                .HasColumnType("int")
                .HasComment("父节点id")
                .IsRequired(true);

            builder
                .Property(menu => menu.NodeType)
                .HasColumnName("NodeType")
                .HasColumnType("nvarchar(256)")
                .HasComment("节点类型")
                .IsRequired(false);

            builder
                .Property(menu => menu.LinkUrl)
                .HasColumnName("LinkUrl")
                .HasColumnType("varchar(1000)")
                .HasComment("url")
                .IsRequired(false);

            builder
                .Property(menu => menu.Level)
                .HasColumnName("Level")
                .HasColumnType("int")
                .HasComment("节点层级")
                .IsRequired(true);

            builder
                .Property(menu => menu.Path)
                .HasColumnName("Path")
                .HasColumnType("varchar(256)")
                .HasComment("路径")
                .IsRequired(false);

            builder
                .Property(menu => menu.Operation)
                .HasColumnName("Operation")
                .HasColumnType("nvarchar(256)")
                .HasComment("操作")
                .IsRequired(false);

            builder
                .Property(menu => menu.AuthorityValue)
                .HasColumnName("AuthorityValue")
                .HasColumnType("nvarchar(256)")
                .HasComment("权限值")
                .IsRequired(false);

            builder
                .Property(menu => menu.Button)
                .HasColumnName("Button")
                .HasColumnType("nvarchar(256)")
                .HasComment("按钮")
                .IsRequired(false);
        }
    }
}